/**
 *    @file       caes.h
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       01/23/2014 10:28:18 AM
 *
 *    @author     Theophilus (), wangtf418@gmail.com
 */
#ifndef _BF_caes_H_
#define _BF_caes_H_
#include <openssl/aes.h>
#include "comdef.h"

enum bf_aes_keylen_t
{
	BF_AES_KEYLEN_16 = 16,	//128 bits
	BF_AES_KEYLEN_24 = 24,	//192 bits
	BF_AES_KEYLEN_32 = 32	//256 bits
};

class caes
{
public:
	caes();
	~caes();

public:
	bf_int_t set_encryptkey(const bf_uchar_t *key, bf_aes_keylen_t keylen);
	bf_int_t set_decryptkey(const bf_uchar_t *key, bf_aes_keylen_t keylen);
	bf_int_t encrypt(const bf_uchar_t input[16], bf_uchar_t output[16]);
	bf_int_t decrypt(const bf_uchar_t input[16], bf_uchar_t output[16]);

private:
	static bf_int_t encrypt(const bf_uchar_t *key, bf_aes_keylen_t keylen, const bf_uchar_t input[16], bf_uchar_t output[16]);
	static bf_int_t decrypt(const bf_uchar_t *key, bf_aes_keylen_t keylen, const bf_uchar_t input[16], bf_uchar_t output[16]);

	static bf_int_t encrypt(const bf_uchar_t *key, bf_aes_keylen_t keylen, const bf_uchar_t *data, bf_size_t len, std::string &str_out);
	static bf_int_t decrypt(const bf_uchar_t *key, bf_aes_keylen_t keylen, const bf_uchar_t *data, bf_size_t len, std::string &str_out);

private:
	bf_int_t m_ifset_enkey;
	bf_int_t m_ifset_dekey;
	AES_KEY m_encrypt_key;
	AES_KEY m_decrypt_key;
};

#endif

